<template>
    <base-breadcrumb>
      <searchData
        :search-data="searchArr"
        @search2="search"
      />
      <a-card :bordered="false">
        <a-spin :spinning="loading">
        <!-- <title-name title="设计管理工作月报" /> -->
        <list-table
          ref="table"
          :columns="columns"
          :request="loadData"
          :statistics-config="{ use: true, statistics, temp }"
          :exportPermission="{ select: 'ds_044_exp_04', all: 'ds_044_exp_04' }"
          :exportConfig="{ use: true,select: '导出选中',all: '导出全部'}"
          :pageKeys="['pageNum', 'pageSize', 'total']"
        >
          <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
          <div slot="action" slot-scope="text, record">
            <MoreButton>
            <a  v-btn-permission="'ds_044_loo_01'"  @click="handleEdit(record,0)">查看</a>
            <a  v-btn-permission="'ds_044_edi_02'"  v-if="(record.auditStatus == 'DRAFT' || record.auditStatus == 'REJECTED')&&hideBuquBtn()" @click="handleEdit(record,1)">填报</a>
            <approval-button  v-if="record.auditStatus != 'DRAFT'" :id="record.id"></approval-button>
            <a-divider v-btn-permission="'ds_044_exp_03'" type="vertical" v-if="record.auditStatus == 'PAST'"/>
                    <span class="pint"  v-if="record.auditStatus == 'PAST'">
                         <a @click="getPritContent(record)">导出</a>
                     </span>
            </MoreButton>
  
          </div>
        </list-table>
        </a-spin>
      </a-card>
    </base-breadcrumb>
  </template>
  
  <script>
  import {
    getPageMonthDesignList,
    getPageMonthDesignTotal,
    exportWord
  } from '@/api/design/monthlyReport/monthlyWorkReport'
  
  export default {
    name: 'a' + Date.now(),
    data() {
      return {
        loading:false,
        columns: [
          { title: '序号', width: '65px', scopedSlots: { customRender: 'serial' } },
          { title: '月度', dataIndex: 'yearmonth' },
          { title: '填报时间', dataIndex: 'editDate' },
          { title: '填报人', width: '100px', dataIndex: 'editUser' },
          { title: '状态', width: '100px', dataIndex: 'auditStatusStr' },
          { title: '操作', dataIndex: 'action', width: 240, scopedSlots: { customRender: 'action' } }
        ],
        searchArr: [
        {name: '月份',value: 'yearmonth',type: 'month'},
          {
            name: '状态', value: 'auditStatus', type: 'select',
            data: [
              { value: '0', label: '待填报' },
              { value: '1', label: '审批中' },
              { value: '2', label: '审批通过' },
              { value: '3', label: '审批不通过' }
            ]
          }
        ],
        data: [],
        queryParam: {},
        // 加载数据方法 必须为 Promise 对象
        loadData: async parameter => {
          this.getMonthlyReportsTotalReq()
          const requestParameters = Object.assign({}, parameter, {param:this.queryParam})
          let res = await getPageMonthDesignList({}, requestParameters)
          if (res.code === this.SUCCESS_CODE) {
            return { code: 200, ...res.data, data: res.data.list }
          }
          return { code: 200, data: [] }
        },
        temp: () => {
          return (
            <span style="margin-right: 12px">
            待填写：<span class="totalNum">{this.statistics.draftNum || 0} 个</span> |
            审批中：<span class="totalNum">{this.statistics.submittedNum || 0} 个</span> |
            审批不通过：<span class="totalNum">{this.statistics.rejectedNum || 0} 个</span> |
            审批通过：<span class="totalNum">{this.statistics.pastNum || 0} 个</span>
          </span>
            // 审批通过的项目设计优化目标指标：<span class="totalNum">{this.statistics.pastOptimizeTarget || 0} 万</span>
          )
        },
        statistics: {},  // 统计
      }
    },
    created() {
    },
    computed: {},
    methods: {
      // 条件搜索
      search(val) {
        this.queryParam = val
        this.$refs.table.refresh(true)
      },
      // 列表统计
      async getMonthlyReportsTotalReq() {
        let res = await getPageMonthDesignTotal({}, this.queryParam)
        if (res.code === this.SUCCESS_CODE) {
          this.statistics = res.data
        }
      },
      // 编辑
      handleEdit(record,editModel) {
        let query = {}
            if (record && record.id) {
                query.id = record.id
                query.month = record.month
            }
            query.editModel = editModel
        this.$router.push({
                name: 'updateWorkReport',
                query
            })
      },
     // 打印  
         async getPritContent(data) {
        this.loading = true;
         let res = await exportWord({id:data.id});
         this.handleDownload(res,data)
         this.loading = false;
        },

        
          /**
     * 转义下载
     * @param parameter
     */
    handleDownload(res,data) {
      let blob = new Blob([res], { type: 'application/doc' })
      const downloadElement = document.createElement('a')
      const href = window.URL.createObjectURL(blob) // 创建下载的链接
      downloadElement.href = href
      downloadElement.download = `${data.yearmonth}设计管理工作月报.doc` // 获取文件名
      document.body.appendChild(downloadElement)
      downloadElement.click() //点击下载
      document.body.removeChild(downloadElement) //下载完成移除元素
      window.URL.revokeObjectURL(href) //释放blob对象
    },
    }
  }
  </script>
  
  